/**
* @file pic.h
* Programmable Interrupt Controller interface for X86 platform.
* Contains data structures and function for PIC managment:
* to send commands to PIC, to send/read data to/from PIC, to init PIC, 
* Inicialization Control Words constants etc...
*
* Copyrights 2010 Michal Saman, m.saman@designplus.cz
* This source code is release under the Apache License 2.0.
*/
#ifndef _PIC_H
#define _PIC_H

#ifndef ARCH_X86
#error "[pic.h] is platform-independent. Define ARCH_X86."
#endif

#include <stdint.h>

/**
* Helper constants to define devices connected to PIC.
* May bey useful when enabling and disbaling IRQ's
*/
// this devices uses PIC1 to generate interrupts
#define PIC_IRQ_TIME		0
#define PIC_IRQ_KEYBOARD	1
#define PIC_IRQ_SERIAL2		3
#define	PIC_IRQ_SERIAL1		4
#define	PIC_IRQ_PARALLEL2	5
#define	PIC_IRQ_DISKETTE	6
#define	PIC_IRQ_PARALLEL1	7
// this devices use PIC2 to generate interrupts
#define PIC_IRQ_CMOSTIMER	0
#define	PIC_IRQ_CGARETRACE	1
#define	PIC_IRQ_AUXILIARY	4
#define	PIC_IRQ_FPU			5
#define	PIC_IRQ_HDC			6

/**
* Helper constants used as command words for device control over PIC.
*/
// Command Word 2 bit masks.
#define PIC_OCW2_MASK_L1		1		// 00000001
#define	PIC_OCW2_MASK_L2		2		// 00000010
#define	PIC_OCW2_MASK_L3		4		// 00000100
#define PIC_OCW2_MASK_EOI		0x20	// 00100000
#define PIC_OCW2_MASK_SL		0x40	// 01000000
#define PIC_OCW2_MASK_ROTATE	0x80	// 10000000

// Command Word 3 bit masks.
#define PIC_OCW3_MASK_RIS		1		// 00000001
#define PIC_OCW3_MASK_RIR		2		// 00000010
#define PIC_OCW3_MASK_MODE		4		// 00000100
#define PIC_OCW3_MASK_SMM		0x20	// 00100000
#define PIC_OCW3_MASK_ESMM		0x40	// 01000000
#define PIC_OCW3_MASK_D7		0x80	// 10000000

extern uint8_t pic_read_data(uint8_t pic_num);
extern void pic_send_data(uint8_t data, uint8_t pic_num);
extern void pic_send_command(uint8_t cmd, uint8_t pic_num);
extern void pic_init(uint8_t base0, uint8_t base1);

//extern void pic_mask_irq(uint8_t irq_mask, uint8_t pic_num);

#endif
